/*
 *此javaCode由YMS-JDBC替换工具生成，原mapper位置com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.PrelableMapper
 */
package com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.impl;

import com.yonyou.iuap.yms.api.IYmsJdbcApi;
import com.yonyou.iuap.yms.param.*;
import com.yonyou.iuap.yms.param.ResultSetProcessor;
import com.yonyou.iuap.yms.processor.*;
import com.yonyou.iuap.yms.replace.CollectionUtil;
import com.yonyou.ucf.mdf.app.isvdxq.secondpart.entity.PrelableEntity;

import java.sql.Types;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class PrelableMapperImpl {
    
    @Autowired
    private IYmsJdbcApi ymsJdbcApi;
    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.PrelableMapper.selectByOrder
    
    public List<PrelableEntity> selectByOrder(String orderid, String orderdetailid, int status, String tenant_id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from isv_prelable where `dr`=0 and ytenant_id=?  and orderid=? and orderdetailid=?  and status=?;\n";
        parameter.addParam(tenant_id);
		parameter.addParam(orderid);
		parameter.addParam(orderdetailid);
		parameter.addParam(status);

        ResultSetProcessor processor = new AutoBeanListProcessor(new PrelableEntity());
        return (List<PrelableEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.PrelableMapper.selectAll
    
    public List<PrelableEntity> selectAll(String tenant_id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from isv_prelable where `dr`=0 and ytenant_id=?;\n";
        parameter.addParam(tenant_id);

        ResultSetProcessor processor = new AutoBeanListProcessor(new PrelableEntity());
        return (List<PrelableEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.PrelableMapper.updateByPrimaryIds
    
    public int updateByPrimaryIds(List<String> strList, String tenant_id, String batchNum) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" update isv_prelable set `status` = 1, batchno_dxq = ? ");
		parameter.addParam(batchNum);
		sqlBuilder.append(" where ytenant_id=? and dr=0 ");
		parameter.addParam(tenant_id);
		if (CollectionUtil.isNotEmpty(strList)) {
			sqlBuilder.append(" and `id` in ( ");
			String separator0 = " , ";
			for (int index = 0; index < strList.size(); index++) {
				String item = strList.get(index);
				sqlBuilder.append(" ? ");
				parameter.addParam(item);
				if (index < strList.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
			sqlBuilder.append(" ) ");
		}else{
			sqlBuilder.append(" and `id` in ( '' )");
		}

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.PrelableMapper.selectByEpc
    
    public PrelableEntity selectByEpc(String epc, String tenant_id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from isv_prelable where `dr`=0 and epccode=? and ytenant_id=? limit 1;";
        parameter.addParam(epc);
		parameter.addParam(tenant_id);

        ResultSetProcessor processor = new AutoBeanProcessor(new PrelableEntity());
        return (PrelableEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.PrelableMapper.selectByIds
    
    public List<PrelableEntity> selectByIds(List<String> strList, String tenant_id) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" select * from isv_prelable where `dr`=0 ");
		if (CollectionUtil.isNotEmpty(strList)) {
			sqlBuilder.append(" and `id` in ( ");
			String separator0 = " , ";
			for (int index = 0; index < strList.size(); index++) {
				String item = strList.get(index);
				sqlBuilder.append(" ? ");
				parameter.addParam(item);
				if (index < strList.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
			sqlBuilder.append(" ) ");
		}
		sqlBuilder.append(" and ytenant_id=?; ");
		parameter.addParam(tenant_id);

        
        String sql = sqlBuilder.toString();
        ResultSetProcessor processor = new AutoBeanListProcessor(new PrelableEntity());
        return (List<PrelableEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.PrelableMapper.updateByPrimaryKey
    
    public int updateByPrimaryKey(PrelableEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update isv_prelable set `creator` = ?, `createTime` = ?, `modifier` = ?, `modifyTime` = ?, `pubts` = ?, `dr` = ?, `pkTemp` = ?, `version` = ?, `ytenantId` = ?, `stockNum` = ?, `epc_tid` = ?, `epccode` = ?, `orderid` = ?, `orderdetailid` = ?, `productId` = ?, `productskuId` = ?, `status` = ?, `batchno` = ?, `productdate` = ? where `id` = ?\n";
        parameter.addParamWithType(record.getCreator(), Types.VARCHAR);
		parameter.addParamWithType(record.getCreateTime(), Types.TIMESTAMP);
		parameter.addParamWithType(record.getModifier(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifyTime(), Types.TIMESTAMP);
		parameter.addParamWithType(record.getPuts(), Types.VARCHAR);
		parameter.addParamWithType(record.getDr(), Types.INTEGER);
		parameter.addParamWithType(record.getPkTemp(), Types.INTEGER);
		parameter.addParamWithType(record.getVersion(), Types.INTEGER);
		parameter.addParamWithType(record.getYtenant_id(), Types.VARCHAR);
		parameter.addParamWithType(record.getStockNum(), Types.DECIMAL);
		parameter.addParamWithType(record.getEpc_tid(), Types.VARCHAR);
		parameter.addParamWithType(record.getEpccode(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrderid(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrderdetailid(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductId(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductskuId(), Types.VARCHAR);
		parameter.addParamWithType(record.getStatus(), Types.INTEGER);
		parameter.addParamWithType(record.getBatchno(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductdate(), Types.VARCHAR);
		parameter.addParamWithType(record.getId(), Types.INTEGER);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.PrelableMapper.insertBatch
    
    public int insertBatch(List<PrelableEntity> insertBatch) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" insert into isv_prelable (`id`, `creator`, `createTime`, `modifier`, `modifyTime`, `pubts`, `dr`, `pkTemp`, `version`, `ytenant_id`, `stockNum`,`epc_tid`, `epccode`, `orderid`,`orderdetailid`, `productId`, `productskuId`, `status`,`batchno`,`productdate`) values ");
		if (CollectionUtil.isNotEmpty(insertBatch)) {
			String separator0 = " , ";
			for (int i = 0; i < insertBatch.size(); i++) {
				PrelableEntity item = insertBatch.get(i);
				sqlBuilder.append(" (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?, ?, ?, ?) ");
				parameter.addParamWithType(item.getId(), Types.INTEGER);
				parameter.addParamWithType(item.getCreator(), Types.VARCHAR);
				parameter.addParamWithType(item.getCreateTime(), Types.TIMESTAMP);
				parameter.addParamWithType(item.getModifier(), Types.VARCHAR);
				parameter.addParamWithType(item.getModifyTime(), Types.TIMESTAMP);
				parameter.addParamWithType(item.getPuts(), Types.VARCHAR);
				parameter.addParamWithType(item.getDr(), Types.INTEGER);
				parameter.addParamWithType(item.getPkTemp(), Types.INTEGER);
				parameter.addParamWithType(item.getVersion(), Types.INTEGER);
				parameter.addParamWithType(item.getYtenant_id(), Types.VARCHAR);
				parameter.addParamWithType(item.getStockNum(), Types.DECIMAL);
				parameter.addParamWithType(item.getEpc_tid(), Types.VARCHAR);
				parameter.addParamWithType(item.getEpccode(), Types.VARCHAR);
				parameter.addParamWithType(item.getOrderid(), Types.VARCHAR);
				parameter.addParamWithType(item.getOrderdetailid(), Types.VARCHAR);
				parameter.addParamWithType(item.getProductId(), Types.VARCHAR);
				parameter.addParamWithType(item.getProductskuId(), Types.VARCHAR);
				parameter.addParamWithType(item.getStatus(), Types.INTEGER);
				parameter.addParamWithType(item.getBatchno(), Types.VARCHAR);
				parameter.addParamWithType(item.getProductdate(), Types.VARCHAR);
				if (i < insertBatch.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
		}
		sqlBuilder.append(" ON DUPLICATE KEY UPDATE epc_tid=VALUES(epc_tid),epccode=VALUES(epccode) ,stockNum=VALUES(stockNum), status=VALUES(status) ,orderid=VALUES(orderid), orderdetailid=VALUES(orderdetailid) ,productId=VALUES(productId), productskuId=VALUES(productskuId) ,modifyTime=VALUES(modifyTime), modifier=VALUES(modifier) ,batchno=VALUES(batchno), productdate=VALUES(productdate) ");

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.PrelableMapper.insert
    
    public int insert(PrelableEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "insert into isv_prelable (`id`, `creator`,  `createTime`, `modifier`,  `modifyTime`, `pubts`,  `dr`, `pkTemp`, `version`, `ytenantId`,  `stockNum`,`epc_tid`, `epccode`,  `orderid`,`orderdetailid`, `productId`,  `productskuId`, `status`,`batchno`,`productdate`) values (?, ?,  ?, ?,  ?, ?,  ?, ?, ?,  ?,  ?, ?,?,  ?, ?, ?,  ?, ?, ?, ? )\n";
        parameter.addParamWithType(record.getId(), Types.INTEGER);
		parameter.addParamWithType(record.getCreator(), Types.VARCHAR);
		parameter.addParamWithType(record.getCreateTime(), Types.TIMESTAMP);
		parameter.addParamWithType(record.getModifier(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifyTime(), Types.TIMESTAMP);
		parameter.addParamWithType(record.getPuts(), Types.VARCHAR);
		parameter.addParamWithType(record.getDr(), Types.INTEGER);
		parameter.addParamWithType(record.getPkTemp(), Types.INTEGER);
		parameter.addParamWithType(record.getVersion(), Types.INTEGER);
		parameter.addParamWithType(record.getYtenant_id(), Types.VARCHAR);
		parameter.addParamWithType(record.getStockNum(), Types.DECIMAL);
		parameter.addParamWithType(record.getEpc_tid(), Types.VARCHAR);
		parameter.addParamWithType(record.getEpccode(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrderid(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrderdetailid(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductId(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductskuId(), Types.VARCHAR);
		parameter.addParamWithType(record.getStatus(), Types.INTEGER);
		parameter.addParamWithType(record.getBatchno(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductdate(), Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.PrelableMapper.selectById
    
    public PrelableEntity selectById(String id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from isv_prelable where `id`=? limit 1;";
        parameter.addParam(id);

        ResultSetProcessor processor = new AutoBeanProcessor(new PrelableEntity());
        return (PrelableEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.PrelableMapper.deleteByPrimaryKey
    
    public int deleteByPrimaryKey(Integer id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "delete from isv_prelable where `id` = ?\n";
        parameter.addParamWithType(id, Types.INTEGER);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.secondpart.mapper.PrelableMapper.deleteByPrimaryIds
    
    public int deleteByPrimaryIds(List<String> strList, String tenant_id) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" delete from isv_prelable where dr=0 ");
		if (CollectionUtil.isNotEmpty(strList)) {
			sqlBuilder.append(" and `id` in ( ");
			String separator0 = " , ";
			for (int index = 0; index < strList.size(); index++) {
				String item = strList.get(index);
				sqlBuilder.append(" ? ");
				parameter.addParam(item);
				if (index < strList.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
			sqlBuilder.append(" ) ");
		}else{
			sqlBuilder.append(" and `id` in ( '' ) ");
		}
		sqlBuilder.append(" and ytenant_id=?;");
		parameter.addParam(tenant_id);

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }

}
